/**
 * 我的持仓记录管理初始化
 */
var MyGpcHistory = {
    id: "MyGpcHistoryTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
MyGpcHistory.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
		{title: '代码', field: 'gScode', visible: true, align: 'center', valign: 'middle'},
		{title: '名称', field: 'gName', visible: true, align: 'center', valign: 'middle'},
		{title: '所属行业', field: 'gOwerBk', visible: true, align: 'center', valign: 'middle'},
		{title: '最新价', field: 'gPrice', visible: true, align: 'center', valign: 'middle'},
		{title: '控盘度', field: 'JGCYDType', visible: true, align: 'center', valign: 'middle'},
		{title: '总市值(亿)', field: 'gZsz', visible: true, align: 'center', valign: 'middle'},
		{title: '盈亏比(%)', field: 'gQjzdf', visible: true, align: 'center', valign: 'middle'},
		{title: '持仓状态', field: 'gCcStatus', visible: true, align: 'center', valign: 'middle'},
		{title: '持仓日期', field: 'gBuyDate', visible: true, align: 'center', valign: 'middle'},
		{title: '清仓日期', field: 'gSellerDate', visible: true, align: 'center', valign: 'middle'},
    ];
};

/**
 * 检查是否选中
 */
MyGpcHistory.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        MyGpcHistory.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加我的持仓记录
 */
MyGpcHistory.openAddMyGpcHistory = function () {
    var index = layer.open({
        type: 2,
        title: '添加我的持仓记录',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/myGpcHistory/myGpcHistory_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看我的持仓记录详情
 */
MyGpcHistory.openMyGpcHistoryDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '我的持仓记录详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/myGpcHistory/myGpcHistory_update/' + MyGpcHistory.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除我的持仓记录
 */
MyGpcHistory.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/myGpcHistory/delete", function (data) {
            Feng.success("删除成功!");
            MyGpcHistory.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("myGpcHistoryId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询我的持仓记录列表
 */
MyGpcHistory.search = function () {
    var queryData = {};
    queryData['gScode'] = $("#gScode").val();
    MyGpcHistory.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = MyGpcHistory.initColumn();
    var table = new BSTable(MyGpcHistory.id, "/myGpcHistory/list", defaultColunms);
    table.setPaginationType("server");
    MyGpcHistory.table = table.init();
});
